home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP05.ZIP / CHAP05 / SCHMOO / DOCUMENT.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  19KB  |  901 lines

  1. /*
  2.  * DOCUMENT.CPP
  3.  *
  4.  * Implementation of the CSchmooDoc derivation of CDocument as
  5.  * well as an implementation of CPolylineAdviseSink.
  6.  *
  7.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Software Design Engineer
  10.  * Microsoft Systems Developer Relations
  11.  *
  12.  * Internet  :  kraigb@microsoft.com
  13.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  14.  */
  15.  
  16.  
  17. #include "schmoo.h"
  18.  
  19.  
  20.  
  21. /*
  22.  * CSchmooDoc::CSchmooDoc
  23.  * CSchmooDoc::~CSchmooDoc
  24.  *
  25.  * Constructor Parameters:
  26.  *  hInst           HINSTANCE of the application.
  27.  */
  28.  
  29. CSchmooDoc::CSchmooDoc(HINSTANCE hInst)
  30.     : CDocument(hInst)
  31.     {
  32.     m_pPL=NULL;
  33.     m_pPLAdv=NULL;
  34.     m_uPrevSize=SIZE_RESTORED;
  35.     return;
  36.     }
  37.  
  38.  
  39. CSchmooDoc::~CSchmooDoc(void)
  40.     {
  41.     //Clean up the allocations we did in FInit
  42.     if (NULL!=m_pPL)
  43.         delete m_pPL;
  44.  
  45.     if (NULL!=m_pPLAdv)
  46.         delete m_pPLAdv;
  47.  
  48.     return;
  49.     }
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. /*
  57.  * CSchmooDoc::FInit
  58.  *
  59.  * Purpose:
  60.  *  Initializes an already created document window.  The client actually
  61.  *  creates the window for us, then passes that here for further
  62.  *  initialization.
  63.  *
  64.  * Parameters:
  65.  *  pDI             LPDOCUMENTINIT containing initialization parameters.
  66.  *
  67.  * Return Value:
  68.  *  BOOL            TRUE if the function succeeded, FALSE otherwise.
  69.  */
  70.  
  71. BOOL CSchmooDoc::FInit(LPDOCUMENTINIT pDI)
  72.     {
  73.     RECT        rc;
  74.  
  75.     //Change the stringtable range to our customization.
  76.     pDI->idsMin=IDS_DOCUMENTMIN;
  77.     pDI->idsMax=IDS_DOCUMENTMAX;
  78.  
  79.     //Do default initialization
  80.     if (!CDocument::FInit(pDI))
  81.         return FALSE;
  82.  
  83.     //Add the Polyline stuff we need.
  84.     m_pPLAdv=new CPolylineAdviseSink((LPVOID)this);
  85.     m_pPL   =new CPolyline(m_hInst);
  86.  
  87.     //Attempt to create our contained Polyline.
  88.     GetClientRect(m_hWnd, &rc);
  89.     InflateRect(&rc, -8, -8);
  90.  
  91.     if (!m_pPL->FInit(m_hWnd, &rc, WS_CHILD | WS_VISIBLE
  92.         , ID_POLYLINE, m_pPLAdv))
  93.         return FALSE;
  94.  
  95.     return TRUE;
  96.     }
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /*
  105.  * CSchmooDoc::FMessageHook
  106.  *
  107.  * Purpose:
  108.  *  Processes WM_SIZE for the document so we can resize the Polyline.
  109.  *
  110.  * Parameters:
  111.  *  <WndProc Parameters>
  112.  *  pLRes           LRESULT FAR * in which to store the return value
  113.  *                  for the message.
  114.  *
  115.  * Return Value:
  116.  *  BOOL            TRUE to prevent further processing, FALSE otherwise.
  117.  */
  118.  
  119. BOOL CSchmooDoc::FMessageHook(HWND hWnd, UINT iMsg, WPARAM wParam
  120.     , LPARAM lParam, LRESULT FAR *pLRes)
  121.     {
  122.     UINT        dx, dy;
  123.     RECT        rc;
  124.  
  125.     if (WM_SIZE==iMsg)
  126.         {
  127.         //Don't effect the Polyline size to or from minimized state.
  128.         if (SIZE_MINIMIZED!=wParam && SIZE_MINIMIZED !=m_uPrevSize)
  129.             {
  130.             //When we change size, resize any Polyline we hold.
  131.             dx=LOWORD(lParam);
  132.             dy=HIWORD(lParam);
  133.  
  134.             /*
  135.              * If we are getting WM_SIZE in response to a Polyline
  136.              * notification, then don't resize the Polyline window again.
  137.              */
  138.             if (!m_fNoSize && NULL!=m_pPL)
  139.                 {
  140.                 //Resize the polyline to fit the new client
  141.                 SetRect(&rc, 8, 8, dx-8, dy-8);
  142.                 m_pPL->RectSet(&rc, FALSE);
  143.  
  144.                 /*
  145.                  * We consider sizing something that makes the file dirty,
  146.                  * but not until we've finished the create process, which
  147.                  * is why we set fNoDirty to FALSE in WM_CREATE since we
  148.                  * get a WM_SIZE on the first creation.
  149.                  */
  150.                 if (!m_fNoDirty)
  151.                     FDirtySet(TRUE);
  152.  
  153.                 SetRect(&rc, 0, 0, dx, dy);
  154.  
  155.                 if (NULL!=m_pAdv)
  156.                     m_pAdv->OnSizeChange((LPCDocument)this, &rc);
  157.  
  158.                 m_fNoDirty=FALSE;
  159.                 }
  160.             }
  161.  
  162.         m_uPrevSize=wParam;
  163.         }
  164.  
  165.     /*
  166.      * We return FALSE even on WM_SIZE so we can let the default procedure
  167.      * handle maximized MDI child windows appropriately.
  168.      */
  169.     return FALSE;
  170.     }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179. /*
  180.  * CSchmooDoc::Clear
  181.  *
  182.  * Purpose:
  183.  *  Sets all contents in the document back to defaults with no filename.
  184.  *
  185.  * Paramters:
  186.  *  None
  187.  *
  188.  * Return Value:
  189.  *  None
  190.  */
  191.  
  192. void CSchmooDoc::Clear(void)
  193.     {
  194.     //Completely reset the polyline
  195.     m_pPL->New();
  196.  
  197.     CDocument::Clear();
  198.     m_lVer=0;
  199.     return;
  200.     }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. /*
  208.  * CSchmooDoc::ULoad
  209.  *
  210.  * Purpose:
  211.  *  Loads a given document without any user interface overwriting the
  212.  *  previous contents of the Polyline window.  We do this by opening
  213.  *  the file and telling the Polyline to load itself from that file.
  214.  *
  215.  * Parameters:
  216.  *  fChangeFile     BOOL indicating if we're to update the window title
  217.  *                  and the filename from using this file.
  218.  *  pszFile         LPSTR to the filename to load, NULL if the file is
  219.  *                  new and untitled.
  220.  *
  221.  * Return Value:
  222.  *  UINT            An error value from DOCERR_*
  223.  */
  224.  
  225. UINT CSchmooDoc::ULoad(BOOL fChangeFile, LPSTR pszFile)
  226.     {
  227.     //CHAPTER5MOD
  228.     HRESULT         hr;
  229.     LPSTORAGE       pIStorage;
  230.     //End CHAPTER5MOD
  231.  
  232.     if (NULL==pszFile)
  233.         {
  234.         //For a new untitled document, just rename ourselved.
  235.         Rename(NULL);
  236.         m_lVer=VERSIONCURRENT;
  237.         return DOCERR_NONE;
  238.         }
  239.  
  240.     //CHAPTER5MOD
  241.     /*
  242.      * If this is not a Compound File, open the file using STGM_CONVERT
  243.      * in TRANSACTED mode to effectively see old files as a storage with
  244.      * one stream called "CONTENTS" (which is conveniently the name we use
  245.      * in the new files).  We must use STGM_TRANSACTED here or else
  246.      * the old file will be immediately converted on disk:  we only want
  247.      * a converted image in memory from which to read.  In addition,
  248.      * note that we need STGM_READWRITE as well since conversion is
  249.      * inherently a write operation.
  250.      */
  251.  
  252.     pIStorage=NULL;
  253.  
  254.     if (NOERROR!=StgIsStorageFile(pszFile))
  255.         {
  256.         hr=StgCreateDocfile(pszFile, STGM_TRANSACTED | STGM_READWRITE
  257.             | STGM_CONVERT | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  258.  
  259.         if (FAILED(hr))
  260.             {
  261.             //If we were denied write access, try to load the old way
  262.             if (STG_E_ACCESSDENIED==GetScode(hr))
  263.                 m_lVer=m_pPL->ReadFromFile(pszFile);
  264.             else
  265.                 return DOCERR_COULDNOTOPEN;
  266.             }
  267.         }
  268.     else
  269.         {
  270.         hr=StgOpenStorage(pszFile, NULL, STGM_DIRECT | STGM_READ
  271.             | STGM_SHARE_EXCLUSIVE, NULL, 0, &pIStorage);
  272.  
  273.         if (FAILED(hr))
  274.             return DOCERR_COULDNOTOPEN;
  275.         }
  276.  
  277.     if (NULL!=pIStorage)
  278.         {
  279.         m_lVer=m_pPL->ReadFromStorage(pIStorage);
  280.         pIStorage->Release();
  281.         }
  282.     //End CHAPTER5MOD
  283.  
  284.     if (POLYLINE_E_READFAILURE==m_lVer)
  285.         return DOCERR_READFAILURE;
  286.  
  287.     if (POLYLINE_E_UNSUPPORTEDVERSION==m_lVer)
  288.         return DOCERR_UNSUPPORTEDVERSION;
  289.  
  290.     if (fChangeFile)
  291.         Rename(pszFile);
  292.  
  293.     //Importing a file makes things dirty
  294.     FDirtySet(!fChangeFile);
  295.  
  296.     return DOCERR_NONE;
  297.     }
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. /*
  306.  * CSchmooDoc::USave
  307.  *
  308.  * Purpose:
  309.  *  Writes the file to a known filename, requiring that the user has
  310.  *  previously used FileOpen or FileSaveAs in order to have a filename.
  311.  *
  312.  * Parameters:
  313.  *  uType           UINT indicating the type of file the user requested
  314.  *                  to save in the File Save As dialog.
  315.  *  pszFile         LPSTR under which to save.  If NULL, use the current name.
  316.  *
  317.  * Return Value:
  318.  *  UINT            An error value from DOCERR_*
  319.  */
  320.  
  321. UINT CSchmooDoc::USave(UINT uType, LPSTR pszFile)
  322.     {
  323.     LONG        lVer, lRet;
  324.     UINT        uTemp;
  325.     BOOL        fRename=TRUE;
  326.     //CHAPTER5MOD
  327.     HRESULT     hr;
  328.     LPSTORAGE   pIStorage;
  329.     //End CHAPTER5MOD
  330.  
  331.     if (NULL==pszFile)
  332.         {
  333.         fRename=FALSE;
  334.         pszFile=m_szFile;
  335.         }
  336.  
  337.     /*
  338.      * Type 1 is the current version, type 2 is version 1.0 of the Polyline
  339.      * so we use this to send the right version to CPolyline::WriteToFile.
  340.      */
  341.  
  342.     switch (uType)
  343.         {
  344.         case 0:         //From Save, use loaded version.
  345.             lVer=m_lVer;
  346.             break;
  347.  
  348.         case 1:
  349.             lVer=VERSIONCURRENT;
  350.             break;
  351.  
  352.         case 2:
  353.             lVer=MAKELONG(0, 1);    //1.0
  354.             break;
  355.  
  356.         default:
  357.             return DOCERR_UNSUPPORTEDVERSION;
  358.         }
  359.  
  360.     /*
  361.      * If the version the user wants to save is different than the
  362.      * version that we loaded, and m_lVer is not zero (new document),
  363.      * then inform the user of the version change and verify.
  364.      */
  365.     if (0!=m_lVer && m_lVer!=lVer)
  366.         {
  367.         char        szMsg[128];
  368.  
  369.         wsprintf(szMsg, PSZ(IDS_VERSIONCHANGE), (UINT)HIWORD(m_lVer)
  370.             , (UINT)LOWORD(m_lVer), (UINT)HIWORD(lVer), (UINT)LOWORD(lVer));
  371.  
  372.         uTemp=MessageBox(m_hWnd, szMsg, PSZ(IDS_DOCUMENTCAPTION), MB_YESNOCANCEL);
  373.  
  374.         if (IDCANCEL==uTemp)
  375.             return DOCERR_CANCELLED;
  376.  
  377.         //If the user won't upgrade versions, revert to loaded version.
  378.         if (IDNO==uTemp)
  379.             lVer=m_lVer;
  380.         }
  381.  
  382.     //CHAPTER5MOD
  383.     /*
  384.      * For 1.0 files, still use the old code.  For new files, use
  385.      * storages instead
  386.      */
  387.     if (lVer==MAKELONG(0, 1))
  388.         lRet=m_pPL->WriteToFile(pszFile, lVer);
  389.     else
  390.         {
  391.         hr=StgCreateDocfile(pszFile, STGM_DIRECT | STGM_READWRITE
  392.             | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, &pIStorage);
  393.  
  394.         if (FAILED(hr))
  395.             return DOCERR_COULDNOTOPEN;
  396.  
  397.         //Mark this as one of our class
  398.         WriteClassStg(pIStorage, CLSID_Schmoo2Figure);
  399.  
  400.         //Write user-readable class information
  401.         WriteFmtUserTypeStg(pIStorage, m_cf, PSZ(IDS_CLIPBOARDFORMAT));
  402.  
  403.         lRet=m_pPL->WriteToStorage(pIStorage, lVer);
  404.         pIStorage->Release();
  405.         }
  406.     //End CHAPTER5MOD
  407.  
  408.     if (POLYLINE_E_NONE!=lRet)
  409.         return DOCERR_WRITEFAILURE;
  410.  
  411.     //Saving makes us clean
  412.     FDirtySet(FALSE);
  413.  
  414.     //Update the known version of this document.
  415.     m_lVer=lVer;
  416.  
  417.     if (fRename)
  418.         Rename(pszFile);
  419.  
  420.     return DOCERR_NONE;
  421.     }
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428. /*
  429.  * CSchmooDoc::Undo
  430.  *
  431.  * Purpose:
  432.  *  Reverses a previous action.
  433.  *
  434.  * Parameters:
  435.  *  None
  436.  *
  437.  * Return Value:
  438.  *  None
  439.  */
  440.  
  441. void CSchmooDoc::Undo(void)
  442.     {
  443.     m_pPL->Undo();
  444.     return;
  445.     }
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453. /*
  454.  * CSchmooDoc::FClip
  455.  *
  456.  * Purpose:
  457.  *  Places a private format, a metafile, and a bitmap of the display
  458.  *  on the clipboard, optionally implementing Cut by deleting the
  459.  *  data in the current window after rendering.
  460.  *
  461.  * Parameters:
  462.  *  hWndFrame       HWND of the main window.
  463.  *  fCut            BOOL indicating cut (TRUE) or copy (FALSE).
  464.  *
  465.  * Return Value:
  466.  *  BOOL            TRUE if successful, FALSE otherwise.
  467.  */
  468.  
  469. BOOL CSchmooDoc::FClip(HWND hWndFrame, BOOL fCut)
  470.     {
  471.     BOOL            fRet=TRUE;
  472.     HGLOBAL         hMem;
  473.     UINT            i;
  474.  
  475.     //This array is so we can loop over the formats we provide.
  476.     static UINT     rgcf[3]={0, CF_METAFILEPICT, CF_BITMAP};
  477.     const UINT      cFormats=3;
  478.  
  479.     if (!OpenClipboard(hWndFrame))
  480.         return FALSE;
  481.  
  482.     //Clean out whatever junk is in the clipboard.
  483.     EmptyClipboard();
  484.  
  485.     rgcf[0]=m_cf;
  486.  
  487.     for (i=0; i < cFormats; i++)
  488.         {
  489.         //Copy private data first.
  490.         hMem=RenderFormat(rgcf[i]);
  491.  
  492.         if (NULL!=hMem)
  493.             SetClipboardData(rgcf[i], hMem);
  494.         else
  495.             fRet &=FALSE;
  496.         }
  497.  
  498.     //Free clipboard ownership.
  499.     CloseClipboard();
  500.  
  501.     //Delete our current data if copying succeeded.
  502.     if (fRet && fCut)
  503.         {
  504.         m_pPL->New();
  505.         FDirtySet(TRUE);
  506.         }
  507.  
  508.     return fRet;
  509.     }
  510.  
  511.  
  512.  
  513.  
  514.  
  515. /*
  516.  * CSchmooDoc::RenderFormat
  517.  *
  518.  * Purpose:
  519.  *  Renders a specific clipboard format into global memory.
  520.  *
  521.  * Parameters:
  522.  *  cf              UINT format to render.
  523.  *
  524.  * Return Value:
  525.  *  HGLOBAL         Global memory handle containing the data.
  526.  */
  527.  
  528. HGLOBAL CSchmooDoc::RenderFormat(UINT cf)
  529.     {
  530.     HGLOBAL     hMem;
  531.  
  532.     if (cf==m_cf)
  533.         {
  534.         m_pPL->DataGetMem(VERSIONCURRENT, &hMem);
  535.         return hMem;
  536.         }
  537.  
  538.     switch (cf)
  539.         {
  540.         case CF_METAFILEPICT:
  541.             return m_pPL->RenderMetafilePict();
  542.  
  543.         case CF_BITMAP:
  544.             return (HGLOBAL)m_pPL->RenderBitmap();
  545.         }
  546.  
  547.     return NULL;
  548.     }
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556. /*
  557.  * CSchmooDoc::FQueryPaste
  558.  *
  559.  * Purpose:
  560.  *  Determines if we can paste data from the clipboard.
  561.  *
  562.  * Parameters:
  563.  *  None
  564.  *
  565.  * Return Value:
  566.  *  BOOL            TRUE if data is available, FALSE otherwise.
  567.  */
  568.  
  569. BOOL CSchmooDoc::FQueryPaste(void)
  570.     {
  571.     return IsClipboardFormatAvailable(m_cf);
  572.     }
  573.  
  574.  
  575.  
  576.  
  577.  
  578. /*
  579.  * CSchmooDoc::FPaste
  580.  *
  581.  * Purpose:
  582.  *  Retrieves the private data format from the clipboard and sets it
  583.  *  to the current figure in the editor window.
  584.  *
  585.  *  Note that if this function is called, then the clipboard format
  586.  *  is available because the Paste menu item is only enabled if the
  587.  *  format is present.
  588.  *
  589.  * Parameters:
  590.  *  hWndFrame       HWND of the main window.
  591.  *
  592.  * Return Value:
  593.  *  BOOL            TRUE if successful, FALSE otherwise.
  594.  */
  595.  
  596. BOOL CSchmooDoc::FPaste(HWND hWndFrame)
  597.     {
  598.     HGLOBAL         hMem;
  599.     LPPOLYLINEDATA  ppl;
  600.     BOOL            fRet=FALSE;
  601.  
  602.     if (!OpenClipboard(hWndFrame))
  603.         return FALSE;
  604.  
  605.     hMem=GetClipboardData(m_cf);
  606.  
  607.     if (NULL!=hMem)
  608.         {
  609.         ppl=(LPPOLYLINEDATA)GlobalLock(hMem);
  610.  
  611.         //TRUE in wParam to cause PLN_SIZECHANGE notification
  612.         m_pPL->DataSet(ppl, FALSE, TRUE);
  613.         GlobalUnlock(hMem);
  614.  
  615.         FDirtySet(TRUE);
  616.         fRet=TRUE;
  617.         }
  618.  
  619.     CloseClipboard();
  620.     return fRet;
  621.     }
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629. /*
  630.  * CSchmooDoc::ColorSet
  631.  *
  632.  * Purpose:
  633.  *  Changes a color used in our contained Polyline.
  634.  *
  635.  * Parameters:
  636.  *  iColor          UINT index of the color to change.
  637.  *  cr              COLORREF new color.
  638.  *
  639.  * Return Value:
  640.  *  COLORREF        Previous color for the given index.
  641.  */
  642.  
  643. COLORREF CSchmooDoc::ColorSet(UINT iColor, COLORREF cr)
  644.     {
  645.     return m_pPL->ColorSet(iColor, cr);
  646.     }
  647.  
  648.  
  649.  
  650.  
  651.  
  652. /*
  653.  * CSchmooDoc::ColorGet
  654.  *
  655.  * Purpose:
  656.  *  Retrieves a color currently in use in the Polyline.
  657.  *
  658.  * Parameters:
  659.  *  iColor          UINT index of the color to retrieve.
  660.  *
  661.  * Return Value:
  662.  *  COLORREF        Current color for the given index.
  663.  */
  664.  
  665. COLORREF CSchmooDoc::ColorGet(UINT iColor)
  666.     {
  667.     return m_pPL->ColorGet(iColor);
  668.     }
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675. /*
  676.  * CSchmooDoc::LineStyleSet
  677.  *
  678.  * Purpose:
  679.  *  Changes the line style currently used in the Polyline
  680.  *
  681.  * Parameters:
  682.  *  iStyle          UINT index of the new line style to use.
  683.  *
  684.  * Return Value:
  685.  *  UINT            Previous line style.
  686.  */
  687.  
  688.  
  689. UINT CSchmooDoc::LineStyleSet(UINT iStyle)
  690.     {
  691.     return m_pPL->LineStyleSet(iStyle);
  692.     }
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700. /*
  701.  * CSchmooDoc::LineStyleGet
  702.  *
  703.  * Purpose:
  704.  *  Retrieves the line style currently used in the Polyline
  705.  *
  706.  * Parameters:
  707.  *  None
  708.  *
  709.  * Return Value:
  710.  *  UINT            Current line style.
  711.  */
  712.  
  713.  
  714. UINT CSchmooDoc::LineStyleGet(void)
  715.     {
  716.     return m_pPL->LineStyleGet();
  717.     }
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726. /*
  727.  * CPolylineAdviseSink::CPolylineAdviseSink
  728.  * CPolylineAdviseSink::~CPolylineAdviseSink
  729.  *
  730.  * Constructor Parameters:
  731.  *  pv              LPVOID to store in this object
  732.  */
  733.  
  734. CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv)
  735.     {
  736.     m_pv=pv;
  737.     return;
  738.     }
  739.  
  740.  
  741. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  742.     {
  743.     return;
  744.     }
  745.  
  746.  
  747.  
  748.  
  749.  
  750. /*
  751.  * CPolylineAdviseSink::OnPointChange
  752.  *
  753.  * Purpose:
  754.  *  Informs the document that the polyline added or removed a point.
  755.  *
  756.  * Parameters:
  757.  *  None
  758.  *
  759.  * Return Value:
  760.  *  None
  761.  */
  762.  
  763. void CPolylineAdviseSink::OnPointChange(void)
  764.     {
  765.     LPCDocument pDoc=(LPCDocument)m_pv;
  766.  
  767.     pDoc->FDirtySet(TRUE);
  768.     return;
  769.     }
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776. /*
  777.  * CPolylineAdviseSink::OnSizeChange
  778.  *
  779.  * Purpose:
  780.  *  Informs the document that the polyline changed size.
  781.  *
  782.  * Parameters:
  783.  *  None
  784.  *
  785.  * Return Value:
  786.  *  None
  787.  */
  788.  
  789. void CPolylineAdviseSink::OnSizeChange(void)
  790.     {
  791.     LPCSchmooDoc pDoc=(LPCSchmooDoc)m_pv;
  792.     RECT         rc;
  793.     DWORD        dwStyle;
  794.  
  795.     /*
  796.      * Polyline window is informing us that it changed size in
  797.      * response to setting it's data.  Therefore we have to
  798.      * size ourselves accordingly but without moving the screen
  799.      * position of the polyline window.
  800.      */
  801.  
  802.     pDoc->m_fNoSize=TRUE;
  803.  
  804.     //Set the document window size.
  805.     GetWindowRect(pDoc->m_pPL->Window(), &rc);
  806.     InflateRect(&rc, 8, 8);
  807.  
  808.     //Adjust for a window sans menu
  809.     dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
  810.     AdjustWindowRect(&rc, dwStyle, FALSE);
  811.  
  812.     SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  813.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  814.  
  815.     if (NULL!=pDoc->m_pAdv)
  816.         pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
  817.  
  818.     pDoc->m_fNoSize=FALSE;
  819.     pDoc->FDirtySet(TRUE);
  820.  
  821.     return;
  822.     }
  823.  
  824.  
  825.  
  826.  
  827.  
  828. /*
  829.  * CPolylineAdviseSink::OnDataChange
  830.  *
  831.  * Purpose:
  832.  *  Informs the document that the polyline data changed.
  833.  *
  834.  * Parameters:
  835.  *  None
  836.  *
  837.  * Return Value:
  838.  *  None
  839.  */
  840.  
  841. void CPolylineAdviseSink::OnDataChange(void)
  842.     {
  843.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  844.  
  845.     if (NULL!=pDoc->m_pAdv)
  846.         pDoc->m_pAdv->OnDataChange(pDoc);
  847.  
  848.     pDoc->FDirtySet(TRUE);
  849.     return;
  850.     }
  851.  
  852.  
  853.  
  854.  
  855.  
  856. /*
  857.  * CPolylineAdviseSink::OnColorChange
  858.  *
  859.  * Purpose:
  860.  *  Informs the document that the polyline data changed a color.
  861.  *
  862.  * Parameters:
  863.  *  None
  864.  *
  865.  * Return Value:
  866.  *  None
  867.  */
  868.  
  869. void CPolylineAdviseSink::OnColorChange(void)
  870.     {
  871.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  872.  
  873.     pDoc->FDirtySet(TRUE);
  874.     return;
  875.     }
  876.  
  877.  
  878.  
  879.  
  880.  
  881. /*
  882.  * CPolylineAdviseSink::OnLineStyleChange
  883.  *
  884.  * Purpose:
  885.  *  Informs the document that the polyline changed its line style.
  886.  *
  887.  * Parameters:
  888.  *  None
  889.  *
  890.  * Return Value:
  891.  *  None
  892.  */
  893.  
  894. void CPolylineAdviseSink::OnLineStyleChange(void)
  895.     {
  896.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  897.  
  898.     pDoc->FDirtySet(TRUE);
  899.     return;
  900.     }
  901.